package com.itheima.controller.admin;

import com.itheima.DTO.SysRolePageDTO;
import com.itheima.VO.SysRoleVO;
import com.itheima.entity.SysRole;
import com.itheima.json.PageBean;
import com.itheima.result.Result;
import com.itheima.service.SysRoleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/sys_role")
@RequiredArgsConstructor
@RestController
@Slf4j
public class SysRoleController {
    private final SysRoleService sysRoleService;

    @GetMapping("/list")
    public Result<?> page(SysRolePageDTO sysRolePageDTO) {
        PageBean pageBean = sysRoleService.page(sysRolePageDTO.getPage(), sysRolePageDTO.getLimit(), sysRolePageDTO.getName());
        return Result.success(pageBean);
    }

    @GetMapping("/allData")
    public Result<?> allData() {
        List<SysRole> sysRoles = sysRoleService.allData();
        return Result.success(sysRoles);
    }

    @PostMapping("/add")
    public Result<?> add(@RequestBody SysRole sysRole) {
        sysRoleService.insertSysRole(sysRole);
        return Result.success();
    }

    @GetMapping("/rowInfo")
    public Result<?> rowInfo(String id){
        SysRoleVO sysRoleVO = sysRoleService.selectRoleById(id);
        return Result.success(sysRoleVO);
    }


    @GetMapping("/del")
    public Result<?> delete(String id){
        sysRoleService.deleteRoleById(id);
        return Result.success();
    }

    @PostMapping("/update")
    public Result<?> update(@RequestBody SysRole sysRole){
        sysRoleService.update(sysRole);
        return Result.success();
    }
}
